package cn.iot.controller.sys;

import cn.iot.common.dto.ResultMsg;
import cn.iot.sys.service.SysStudentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/sys/student")
public class SysStudentController {
    @Autowired
    private SysStudentService sysStudentService;
    private Logger logger = LoggerFactory.getLogger(getClass());


    @PreAuthorize("@ss.hasPermi('system:student:list')")
    @PostMapping("getSysStudentList")
    public ResultMsg getSysStudentList(@RequestParam Map<String,Object> map){
        logger.info("SysStudentController getSysStudentList map{}",map);
        ResultMsg msg = sysStudentService.getSysStudentList(map);
        logger.debug("SysStudentController getSysStudentList msg{}",msg);
        return msg;
    }

    @PostMapping("addStudent")
    public ResultMsg addStudent(@RequestParam("file") MultipartFile file,@RequestParam Map<String,Object> map){
        logger.info("SysStudentController addStudent map{}",map);
        ResultMsg msg = sysStudentService.addStudent(file,map);
        logger.debug("SysStudentController addStudent msg{}",msg);
        return msg;
    }
    @PostMapping("getSysStudentById")
    public ResultMsg getSysStudentById(@RequestParam int id){
        logger.info("SysStudentController getSysStudentById id{}",id);
        ResultMsg msg = sysStudentService.getSysStudentById(id);
        logger.debug("SysStudentController getSysStudentById msg{}",msg);
        return msg;
    }
    @PostMapping("updSysStudentById")
    public ResultMsg updSysStudentById(@RequestParam("file") MultipartFile file,@RequestParam Map<String,Object> map){
        logger.info("SysStudentController updSysStudentById map{}",map);//@RequestParam("file") MultipartFile file,
//        ResultMsg msg = new ResultMsg();
        ResultMsg msg = sysStudentService.updSysStudentById(file,map);
        logger.debug("SysStudentController updSysStudentById msg{}",msg);
        return msg;
    }

    @PostMapping("updHostelIdByStuId")
    public ResultMsg updDormitoryIdByStuId(@RequestParam Map<String,Object> map){
        logger.info("SysStudentController updDormitoryIdByStuId map{}",map);
        ResultMsg msg = sysStudentService.updHostelIdByStuId(map);
        return msg;
    }

    @PostMapping("delStuById")
    public ResultMsg delStuById(@RequestParam Map<String,Object> map){
        logger.info("SysStudentController delById map{}",map);
        ResultMsg msg = sysStudentService.delById(map);
        return msg;
    }

    @RequestMapping("/uploadStuInfo")
    public ResultMsg uploadClassInfo(@RequestParam("file") MultipartFile file) {
        logger.info("SysClassController uploadClassInfo file{}",file);
        ResultMsg msg = sysStudentService.uploadStudentInfo(file);
        logger.debug("SysClassController uploadClassInfo msg{}",msg);
        return msg;
    }

    @RequestMapping("/uploadStudentPicture")
    public ResultMsg uploadStudentPicture(@RequestParam("file") MultipartFile file){
        logger.info("SysClassController uploadStudentPicture file{}",file);
        ResultMsg msg = sysStudentService.uploadStudentPicture(file);
        logger.debug("SysClassController uploadStudentPicture msg{}",msg);
        return msg;
    }

    @PostMapping("deriveStuInfo")
    public ResultMsg deriveStuInfo(){
        logger.info("SysClassController deriveStuInfo start...");
        ResultMsg msg = sysStudentService.deriveStuInfo();
        logger.debug("SysClassController deriveStuInfo msg{}",msg);
        return msg;
    }

    @PostMapping("getStuListByClassId")
    public ResultMsg getStuListByClassId(@RequestParam int classId){
        logger.info("SysClassController getStuListByClassId classId{}",classId);
        ResultMsg msg = sysStudentService.getStuListByClassId(classId);
        logger.debug("SysClassController getStuListByClassId msg{}",msg);
        return msg;
    }
}
